﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using Jumpton.SFA.Server.BusinessRule.CPR;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class Visit_CPR_Info : PageBase
{
    private String visitId;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            visitId =  Request.QueryString["visitid"];
        }
        catch (Exception)
        {
            return;
        }
        InitPage();

    }
    //加载数据
    private void InitPage()
    {

        DataTable dt = new CPR_Form_Manager().GetCPR_FROM_Table(visitId, "26", "1", "");
        DataTable dtMeasure = dt.Clone();
        foreach (DataRow row in dt.Rows)
        {
            if (dtMeasure.Select("FORM_ID='" + row["FORM_ID"].ToString() + "'").Count() < 1)
                dtMeasure.ImportRow(row);
        }
        rptMeasure.DataSource = dtMeasure;
        rptMeasure.DataBind();

    }


    protected void rptMeasure_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            GridView gv = e.Item.FindControl("gvMeasureTransation") as GridView;
            
            string formId = DataBinder.Eval(e.Item.DataItem, "FORM_ID").ToString();
            DataTable dt = new CPR_Form_Manager().GetCPR_FROM_Table(visitId, "26", "1", " AND c.FORM_ID=" + formId);
            gv.DataSource = dt;
            gv.DataBind();

        }

    }

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
        DataRowView view = e.Row.DataItem as DataRowView;
        //如果是照片，则显示该照片
        if ("6" == view["INPUTTYPE"].ToString().Trim())
        {
            if ("" == view["PHOTO_ID"].ToString())
            {
                e.Row.Cells[1].Text = "无";
            }
            else
            {
                System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                image.BorderStyle = BorderStyle.Solid;
                image.Height = new Unit(80, UnitType.Pixel);
                image.Width = new Unit(80, UnitType.Pixel);
                image.ImageUrl = ServerPath + "IMAGE.aspx?" + view["PHOTO_ID"].ToString();

                e.Row.Cells[1].Controls.Add(image);
            }
        }
    }
}